package com.dts.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dts.Mapper.EmpMapper;
import com.dts.dto.EmpQueryDto;
import com.dts.entity.Emp;
import com.dts.service.EmpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpServiceImpl extends ServiceImpl<EmpMapper, Emp> implements EmpService {

    private static Logger logger = LoggerFactory.getLogger(EmpServiceImpl.class);

    public Emp selectEmpById(int empId) {
        return baseMapper.selectEmpById(empId);
    }

    public List<Emp> selectAllEmp(Emp emp) {
        return baseMapper.selectAllEmp(emp);
    }

    public int insertEmp(Emp emp) {
        return baseMapper.insert(emp);
    }

    public Page<Emp> selectEmpPage(Page<Emp> page, EmpQueryDto dto) {
        LambdaQueryWrapper <Emp> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(dto.getName() != null&& dto.getName().length()>0, Emp::getEmpName,dto.getName());
        wrapper.eq(dto.getId() != null&& dto.getId()!=0, Emp::getEmpId,dto.getId());
        return baseMapper.selectPage(page,wrapper);
    }

    @Override
    public void updateEmp(Emp emp) {
        baseMapper.updateById(emp);
    }

    @Override
    public void deleteEmp(int empId) {
        baseMapper.deleteById(empId);
    }
}


